------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\figure5.log
  log type:  text
 opened on:  14 Jan 2019, 15:51:00

. #delimit ;
delimiter now ;
. *     ***************************************************************** *;
. *     ***************************************************************** *;
. *       File-Name:      figure5.do                                      *;
. *       Date:           January 14, 2019                                *;
. *       Author:         MRG/CC                                          *;
. *       Purpose:        Produce Figure 5 for It's Not Only What You     *;
. *                       Say, It's Also How You Say It: The Strategic    *;
. *                       Use Of Campaign Sentiment. Journal of Politics. *;
. *                       Forthcoming.                                    *;
. *           Input File:     sentiment.dta                                   *;
. *       Output File:    figure5.log                                     *;
. *       Data Output:    none                                            *;
.              *       Previous file:  sentiment.dta                                   *;
. *       Machine:        desktop/laptop                                                  *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *        Load data                                                      *;
. *     ****************************************************************  *;
. use "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\sentiment.dta", clear;

. set more off;

. *     ****************************************************************  *;
. *       Declare data to be panel, where the panel is based on language  *;
. *     ****************************************************************  *;
. xtset language;
       panel variable:  language (unbalanced)

. xtsum positive_sentiment;

Variable         |      Mean   Std. Dev.       Min        Max |    Observations
-----------------+--------------------------------------------+----------------
positi~t overall |  1.696912   1.446166       -.68        7.6 |     N =     421
         between |              1.34797   .4018627     4.3828 |     n =       7
         within  |             .7198334  -1.565888   4.914112 | T-bar = 60.1429

. *     ****************************************************************  *;
. *       Generate additional variables that we will need for our         *;
. *       analysis.                                                       *;
. *     ****************************************************************  *;
. gen incumbent_inflation_l = incumbent*inflation_l;
(21 missing values generated)

. label var incumbent_inflation "incumbent*inflation_l";

. gen incumbent_unemployment_l = incumbent*unemployment_l;
(7 missing values generated)

. label var incumbent_unemployment_l "incumbent*unemployment_l";

. gen incumbent_pm = incumbent*pm;

. label var incumbent_pm "incumbent*pm";

. gen incumbent_fm = incumbent*fm;

. label var incumbent_fm "incumbent*fm";

. gen left_right2=left_right*left_right;
(39 missing values generated)

. label var left_right2 "left_right*left_right";

. gen extremist = 0;

. replace extremist=1 if family_id ==14 | family_id==40;
(87 real changes made)

. replace extremist = . if family_id==.;
(9 real changes made, 9 to missing)

. label var extremist "1 if communist/socialist or far right, 0 otherwise";

. gen extremist2 = 0;

. replace extremist2=1 if family_id ==14 | family_id==40 | family_id==19;
(124 real changes made)

. replace extremist2 = . if family_id==.;
(9 real changes made, 9 to missing)

. label var extremist2 "1 if communist/socialist, far right, or greens, 0 otherwise";

. gen extremist_inflation_l=extremist*inflation_l;
(30 missing values generated)

. label var extremist_inflation "extremist*inflation_l";

. gen extremist_unemployment_l=extremist*unemployment_l;
(16 missing values generated)

. label var extremist_unemployment_l "extremist*unemployment_l";

. tabulate language, gen(l);

   language |      Freq.     Percent        Cum.
------------+-----------------------------------
      Dutch |        102       24.23       24.23
    English |         85       20.19       44.42
     French |         36        8.55       52.97
     German |         46       10.93       63.90
    Italian |         54       12.83       76.72
 Portuguese |         50       11.88       88.60
    Spanish |         48       11.40      100.00
------------+-----------------------------------
      Total |        421      100.00

. *     ****************************************************************  *;
. *      Change graph scheme                                                  *;
. *     ****************************************************************  *;
. *ssc install scheme-burd, replace;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *       Produce Figure 5                                                *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *       Panel (a) Inflation                                             *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. sum inflation_l;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
 inflation_l |        400    4.911179    5.451015  -.9461664   28.78333

. return list;

scalars:
                  r(N) =  400
              r(sum_w) =  400
               r(mean) =  4.911178681254387
                r(Var) =  29.71356266068384
                 r(sd) =  5.451014828514396
                r(min) =  -.9461663961410523
                r(max) =  28.78333282470703
                r(sum) =  1964.471472501755

. scalar standard_deviation=r(sd);

. di standard_deviation;
5.4510148

. matrix crab = J(2,2,.);

. matrix coln crab = estimate se;

. bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist inflation_l incumbent_inflati
> on_l, fe;
(running xtreg on estimation sample)

Bootstrap replications (400)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400

Fixed-effects (within) regression               Number of obs      =       391
Group variable: language                        Number of groups   =         7

R-sq:  within  = 0.2228                         Obs per group: min =        31
       between = 0.4746                                        avg =      55.9
       overall = 0.0015                                        max =       100

                                                Wald chi2(5)       =    107.72
corr(u_i, Xb)  = -0.2237                        Prob > chi2        =    0.0000

                                     (Replications based on 64 clusters in election_id)
---------------------------------------------------------------------------------------
                      |   Observed   Bootstrap                         Normal-based
   positive_sentiment |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
----------------------+----------------------------------------------------------------
            incumbent |   .0522727   .1128164     0.46   0.643    -.1688433    .2733888
         incumbent_pm |   .2331414   .0804999     2.90   0.004     .0753646    .3909183
            extremist |  -.4713886   .1036157    -4.55   0.000    -.6744716   -.2683056
          inflation_l |  -.0404941    .014497    -2.79   0.005    -.0689076   -.0120806
incumbent_inflation_l |   .0379998   .0158698     2.39   0.017     .0068956    .0691041
                _cons |   1.899274   .2017465     9.41   0.000     1.503858     2.29469
----------------------+----------------------------------------------------------------
              sigma_u |  1.4322672
              sigma_e |  .64877972
                  rho |  .82974785   (fraction of variance due to u_i)
---------------------------------------------------------------------------------------

. *     ****************************************************************  *;
. *       For opposition parties                                          *;
. *     ****************************************************************  *;
. lincom inflation_l*standard_deviation;

 ( 1)  5.451015*inflation_l = 0

------------------------------------------------------------------------------
positive_s~t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         (1) |  -.2207338   .0790231    -2.79   0.005    -.3756162   -.0658513
------------------------------------------------------------------------------

. matrix crab[1,1] = r(estimate);

. matrix crab[1,2] = r(se);

. *     ****************************************************************  *;
. *       For incumbent parties                                           *;
. *     ****************************************************************  *;
. lincom (inflation_l + incumbent_inflation_l)*standard_deviation;

 ( 1)  5.451015*inflation_l + 5.451015*incumbent_inflation_l = 0

------------------------------------------------------------------------------
positive_s~t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         (1) |   -.013596   .0807994    -0.17   0.866    -.1719599    .1447678
------------------------------------------------------------------------------

. matrix crab[2,1] = r(estimate);

. matrix crab[2,2] = r(se);

. coefplot (matrix(crab[.,1]), se(crab[.,2]) offset(0) lwidth(medthick) m(smcircle) mfcolor("126 163 204") mlc("126 163 204") 
>             ciop(lcolor("126 163 204"))), legend(off) 
>             xtitle("") ytitle("Effect of Inflation on Positive Sentiment", size(3)) levels(95)   
>             coeflabels(r1="Opposition Party" r2="Incumbent Party", wrap(18) tlcolor(black) labcolor(black) labsize(3)) grid(n) yscale(noline) 
>             ylab(-0.4 -0.3 -0.2 -0.1 0 0.1 0.2, tlcolor(black) labcolor(black) labsize(2.5)) xscale(noline) yline(0, lcolor(gray)) 
>             vertical scheme(burd) name(aaaaaa);

. graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig5a.pdf", replace;
(file C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig5a.pdf written in PDF format)

.        *     ****************************************************************  *;
. *     ****************************************************************  *;
. *       Panel (b) Unemployment                                          *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. sum unemployment_l;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
unemployme~l |        414    8.747821    4.522593      3.137       22.9

. return list;

scalars:
                  r(N) =  414
              r(sum_w) =  414
               r(mean) =  8.747821327568829
                r(Var) =  20.45384752755176
                 r(sd) =  4.522593009275957
                r(min) =  3.13700008392334
                r(max) =  22.89999961853027
                r(sum) =  3621.598029613495

. scalar standard_deviation=r(sd);

. di standard_deviation;
4.522593

. matrix crab = J(2,2,.);

. matrix coln crab = estimate se;

. bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist unemployment_l incumbent_unem
> ployment_l, fe;
(running xtreg on estimation sample)

Bootstrap replications (400)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400

Fixed-effects (within) regression               Number of obs      =       405
Group variable: language                        Number of groups   =         7

R-sq:  within  = 0.1902                         Obs per group: min =        35
       between = 0.0223                                        avg =      57.9
       overall = 0.0172                                        max =       100

                                                Wald chi2(5)       =     94.22
corr(u_i, Xb)  = -0.0970                        Prob > chi2        =    0.0000

                                        (Replications based on 68 clusters in election_id)
------------------------------------------------------------------------------------------
                         |   Observed   Bootstrap                         Normal-based
      positive_sentiment |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------------------+----------------------------------------------------------------
               incumbent |   .3445268   .1381043     2.49   0.013     .0738472    .6152063
            incumbent_pm |   .2563192    .080232     3.19   0.001     .0990673     .413571
               extremist |  -.4538443   .1124822    -4.03   0.000    -.6743054   -.2333832
          unemployment_l |  -.0240029   .0121882    -1.97   0.049    -.0478914   -.0001144
incumbent_unemployment_l |  -.0128492   .0166773    -0.77   0.441    -.0455361    .0198378
                   _cons |   1.915028   .2030541     9.43   0.000     1.517049    2.313006
-------------------------+----------------------------------------------------------------
                 sigma_u |  1.3988999
                 sigma_e |  .63756734
                     rho |  .82800631   (fraction of variance due to u_i)
------------------------------------------------------------------------------------------

. *     ****************************************************************  *;
. *       For opposition parties                                          *;
. *     ****************************************************************  *;
. lincom unemployment_l*standard_deviation;

 ( 1)  4.522593*unemployment_l = 0

------------------------------------------------------------------------------
positive_s~t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         (1) |  -.1085553   .0551225    -1.97   0.049    -.2165934   -.0005173
------------------------------------------------------------------------------

. matrix crab[1,1] = r(estimate);

. matrix crab[1,2] = r(se);

. *     ****************************************************************  *;
. *       For incumbent parties                                           *;
. *     ****************************************************************  *;
. lincom (unemployment_l + incumbent_unemployment_l)*standard_deviation;

 ( 1)  4.522593*unemployment_l + 4.522593*incumbent_unemployment_l = 0

------------------------------------------------------------------------------
positive_s~t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         (1) |  -.1666668   .0735495    -2.27   0.023    -.3108211   -.0225126
------------------------------------------------------------------------------

. matrix crab[2,1] = r(estimate);

. matrix crab[2,2] = r(se);

. coefplot (matrix(crab[.,1]), se(crab[.,2]) offset(0) lwidth(medthick) m(smcircle) mfcolor("126 163 204") mlc("126 163 204") 
>         ciop(lcolor("126 163 204"))), legend(off) 
>         xtitle("") ytitle("Effect of Unemployment on Positive Sentiment", size(3)) levels(95)   
>         coeflabels(r1="Opposition Party" r2="Incumbent Party", wrap(18) tlcolor(black) labcolor(black) labsize(3)) grid(n) yscale(noline) 
>         ylab(, tlcolor(black) labcolor(black) labsize(2.5)) xscale(noline) yline(0, lcolor(gray)) vertical scheme(burd) name(bbbbbb);

.         graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig5b.pdf", replace;
(file C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig5b.pdf written in PDF format)

.          gr combine aaaaaa bbbbbb;

. graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig5.pdf", replace;
(file C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig5.pdf written in PDF format)

. *     ****************************************************************  *;
. *       Replication complete                                            *;
. *     ****************************************************************  *;
. log close;
      name:  <unnamed>
       log:  C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\figure5.log
  log type:  text
 closed on:  14 Jan 2019, 15:51:13
------------------------------------------------------------------------------------------------------------------------------------------------
